﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace VictorBlaga.DocumentManagement.Core.Services.Impl
{
    public class CryptographerService : ICryptographerService
    {
        public string CreateSalt()
        {
            int size = 64;
            //Generate a cryptographic random number.
            var rng = new RNGCryptoServiceProvider();
            var buff = new byte[size];
            rng.GetBytes(buff);

            // Return a Base64 string representation of the random number.
            return Convert.ToBase64String(buff);
        }

        public string GetPasswordHash(string password, string salt)
        {
            return ComputeHash(password + "mvcpath.blogspot.com" + salt);
        }

        private string ComputeHash(string valueToHash)
        {
            HashAlgorithm algorithm = SHA512.Create();
            byte[] hash = algorithm.ComputeHash(Encoding.UTF8.GetBytes(valueToHash));

            return Convert.ToBase64String(hash);
        }
    }
}
